# NFakeMail - A fake SMTP Server for software testing.
# 
# Copyright (C) 2010, Joao Angelo
# 
# This file is part of NFakeMail.
#
# NFakeMail is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# NFakeMail is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with NFakeMail; if not, see <http://www.gnu.org/licenses/>.

import sys
import os
import asyncore
import smtpd

server = None

class FakeSmtpServer(smtpd.SMTPServer):

    def __init__(self, localaddr, remoteaddr):
        smtpd.SMTPServer.__init__(self, localaddr, remoteaddr)

    def process_message(self, peer, mailfrom, rcpttos, data):
		receiver.ReceiveMessage(peer[0], peer[1], mailfrom, rcpttos, data)

def Start(host, port):
	global server
	server = FakeSmtpServer((host, port), None)
	asyncore.loop(5)

def Stop():
	server.close()


